<template>
	<!-- 发布找活 -->

	<view class="content">
		<u-form :model="form" ref="uForm">
			<u-form-item label="工种类型" label-width='100px'>
				<u-input v-model="form.work_type" input-align="right"  placeholder="请选择" disabled="true" type="select"  @click="jobShow=true" />
				<!-- <u-select v-model="jobShow" :list="jobList" @confirm="workType"></u-select> -->
				<u-picker mode="selector" v-model="jobShow"  :default-selector="[0]" :range="jobList" range-key="label" @confirm="workType"></u-picker>
			</u-form-item>
			<u-form-item label="工人人数"  label-width='100px'>
				<u-input v-model="form.number" placeholder="请输入" input-align="right" />
			</u-form-item>
			<u-form-item label="空闲开始时间" label-width='100px'>
				<u-input v-model="form.begin_date" @click="beginTime" placeholder="请选择" disabled="true" type="select"  input-align="right" />
				<u-calendar v-model="beginShow" :mode="mode" max-date="3000-08-09" @change='changeBegin'></u-calendar>
			</u-form-item>
			<u-form-item label="空闲结束时间" label-width='100px'>
				<u-input v-model="form.end_date" @click="endTime" placeholder="请选择" disabled="true" type="select"  input-align="right" />
				<u-calendar v-model="endShow" max-date="3000-08-09" :mode="mode" @change='changeEnd'></u-calendar>
			</u-form-item>
			<u-form-item label="承接区域" label-width='100px'>
				<u-input v-model="form.area" input-align="right" placeholder="请选择" disabled="true" type="select"  @click="areaShow=true" />
				<u-select v-model="areaShow" mode="mutil-column-auto" :list="cityList" @confirm="cityName"></u-select>
			</u-form-item>
			<u-form-item label="发布周期" label-width='100px'>
				<u-input v-model="form.recruitment_cycle" disabled="true" placeholder="请选择" type="select"  input-align="right" @click="cycleShow=true" />
				<!-- <u-select v-model="cycleShow" :list="cycleList" @confirm="cycleConfirm"></u-select> -->
				<u-picker mode="selector" v-model="cycleShow"  :default-selector="[0]" :range="cycleList" range-key="label" @confirm="cycleConfirm"></u-picker>
			</u-form-item>
			<u-form-item label="联系人" label-width='100px'>
				<u-input v-model="form.contacts" placeholder="请输入" input-align="right" />
			</u-form-item>
			<u-form-item label="联系方式" label-width='100px'>
				<u-input v-model="form.contacts_method" placeholder="请输入" input-align="right" />
			</u-form-item>
		</u-form>
		<view class="footer">
			<div class="foot" @click="cancel">取消</div>
			<!-- <div class="foot_ter" @click="upload">暂存</div> -->
			<div class="foot_ter" @click="submit">提交</div>
		</view>
	</view>
</template>

<script>
	import api from '@/static/js/api.js'
	import request from '@/static/js/request.js'
	export default {
		data() {
			return {
				form: {
					
					work_type: "",
					work_type_id: '',
					begin_date: '',
					end_date: '',
					recruitment_cycle: '',
					number: '',
					area: '',
					userInfo: '',
					contacts: '',
					contacts_method: '',
				},
				mode: 'date',
				beginShow: false,
				endShow: false,
				jobShow: false,
				areaShow: false,
				cycleShow: false,
				cycleList: [

					{
						value: '1',
						label: '今天'
					},
					{
						value: '2',
						label: '3天'
					}, {
						value: '3',
						label: '7天'
					}

				],

				jobList: [],
				cityList: [],
				province_id: '',
				city_id: '',
				area_id: '',
			}
		},
		onShow() {
			this.userinfo = JSON.parse(uni.getStorageSync('userInfo'));
			this.cityListMethod()
			this.tageMethod()
		},
		methods: {
			beginTime() {
				this.beginShow = true
			},
			endTime() {
				this.endShow = true
			},
			changeBegin(e) {
				this.form.begin_date = e.result
			},
			changeEnd(e) {
				this.form.end_date = e.result
			},
			cycleConfirm(e) {
				this.form.recruitment_cycle = this.cycleList[e[0]].label
			},
			workType(e) {
				this.form.work_type = this.jobList[e[0]].label
				this.form.work_type_id = this.jobList[e[0]].value
			},
			cityName(e) {
				console.log(e, '999999999999')
				if (e[0].label == e[1].label) {
					this.form.area = e[0].label + ' ' + e[2].label
				} else {
					this.form.area = e[0].label + ' ' + e[1].label + ' ' + e[2].label
				}
				this.province_id = e[0].value
				this.city_id = e[1].value
				this.area_id = e[2].value
			},
			cityListMethod() {
				api.cityApi('res.country.state', '_api_get_information_in_bulk_area', this.userinfo.access_token).then(
					res => {
						let objData = res.data.tag
						for (let key in objData) {
							let obj = {}
							obj.value = objData[key]
							obj.label = key
							this.jobList.push(obj)
						}
						this.cityList = res.data

					}).catch(e => {
					uni.showToast({
						icon: 'none',
						title: e.message
					})
				})
			},
			tageMethod(){
				api.cityApi('res.country.state', '_api_get_information_in_bulk_area_reverse', this.userinfo.access_token).then(
					res => {
						let objData = res.data.tag
						for (let key in objData) {
							let obj = {}
							obj.value = objData[key]
							obj.label = key
							this.jobList.push(obj)
						}
					}).catch(e => {
					uni.showToast({
						icon: 'none',
						title: e.message
					})
				})
			},
			cancel(){
				uni.switchTab({
					url:"../../pages/main/mine"
				})
			},
			submit() {
				
				if(this.form.work_type==''){
					uni.showToast({
						icon: 'none',
						title: '请选择工种类型'
					})
					return
				}
				if(this.form.number==''){
					uni.showToast({
						icon: 'none',
						title: '请填写工人人数'
					})
					return
				}
				if(this.form.begin_date==''){
					uni.showToast({
						icon: 'none',
						title: '请选择空闲开始时间'
					})
					return
				}
				if(this.form.end_date==''){
					uni.showToast({
						icon: 'none',
						title: '请选择空闲结束时间'
					})
					return
				}
				if(this.form.area==''){
					uni.showToast({
						icon: 'none',
						title: '请选择承接区域'
					})
					return
				}
				if(this.form.recruitment_cycle ==''){
					uni.showToast({
						icon: 'none',
						title: '请选择发布周期'
					})
					return
				}if(this.form.contacts==''){
					uni.showToast({
						icon: 'none',
						title: '请填写联系人'
					})
					return
				}if(this.form.contacts_method==''){
					uni.showToast({
						icon: 'none',
						title: '请填写联系方式'
					})
					return
				}
				let data = {
					model: "jhj.work.release",
					function_name: "_api_jhj_work_release",
					access_token: this.userinfo.access_token,
					uid: this.userinfo.uid,
					partner_id: this.userinfo.partner_id,
					userInfo: JSON.stringify([{
						"work_type": this.form.work_type_id,
						"number": this.form.number
					}]),
					begin_date: this.form.begin_date,
					end_date: this.form.end_date,
					recruitment_cycle: this.form.recruitment_cycle,
					areaIdList:JSON.stringify([{
						"state": this.province_id,
						"city": this.city_id,
						"area": this.area_id
					}]),
					contacts: this.form.contacts,
					contacts_method: this.form.contacts_method
				};
				request.post('/api/v1/getattr/0', data).then(resp => {
                    uni.switchTab({
                    	url: '../../pages/main/mine'
                    })
				}).catch(e => {
					uni.showToast({
						icon: 'none',
						title: e.message
					})
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	.content {
		padding: 20rpx 20rpx;

		.footer {
			display: flex;
			justify-content: center;
			margin-top: 30rpx;

			.foot,
			.foot_ter {
				padding: 15rpx 40rpx;
				border: 2rpx solid #DD524D;
				border-radius: 10rpx;
				font-size: 30rpx;
			}

			.foot {
				color: #DD524D;
			}

			.foot_ter {
				margin-left: 20rpx;
				background-color: #DD524D;
				color: #FFFFFF;

			}
		}
	}
</style>
